package utils;

import controllers.App;
import models.sys.User;
import play.mvc.Scope.Session;

public class SessionUtils {

    public static final String USER_SESSION_KEY = "user_id";

    public static Long getLong(String key) {
        return Session.current().contains(key) ? Long.parseLong(Session.current().get(key)) : -1;
    }

    public static User getCurrentUser() {
        return (User) (getLong(USER_SESSION_KEY) > -1 ? User.findById(getLong(USER_SESSION_KEY)) : null);
    }

    public static void setCurrentUser(User user) {
        Session.current().put(USER_SESSION_KEY, user.id);
    }

    public static void clear() {
        Session.current().clear();
    }
}
